package DoublePointer;

import org.junit.Test;

import java.util.Arrays;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: DoublePointer
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-11-03  18:42
 * @Description: TODO
 * @Version: 1.0
 */
public class 有序数组平方977 {

    public int[] sortedSquares(int[] nums) {
        int[] result=new int[nums.length];
        int index=result.length-1;
        int left=0;
        int right=nums.length-1;
        while (left<=right){
            if (nums[left]*nums[left]>=nums[right]*nums[right]){
                result[index--]=nums[left]*nums[left];
                left++;
            }else {
                result[index--]=nums[right]*nums[right];
                right--;
            }
        }
        return result;
    }

    @Test
    public void test(){
        int[] ints = sortedSquares(new int[]{-7});
        System.out.println(Arrays.toString(ints));
    }
}
